package com.watson.websocket.config1;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author watson
 * @date 2021/8/4 16:30
 * @Description: TODO
 **/
@RestController
public class MyWebDemoController {
    @Autowired
//    MYWebSocketHandler webSocket;
            WebSocket webSocket;

    @GetMapping("send")
    public void sendTest() {
        System.out.println("begin");
        for (int i = 0; i < 10; i++) {
            byte[] fds = new byte[2014];
//            webSocket.sendMessageToUsers(new TextMessage(String.valueOf(i).getBytes()));
            webSocket.sendMessage(String.valueOf(i));
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("end");
    }
}
